home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-05-24 | 2.2 KB | 60 lines | [TEXT/MPS ] |
- From the Mail Bag
- After looking at the April issue (with the articles on the Code Fragment
- Manager and calling 68K code from PowerPC code), some developers have
- asked “how do I call PowerPC code from 68K code?”
-
- If you want to leave the 68K code alone, you need to construct one or
- more Routine Descriptors in the PowerPC code and pass the addresses of
- these (Universal Procedure Pointers, in other words) to the 68K code.
- Then, the 68K code can simply jump through the universal pointer.
-
- The PowerPC code can provide a function whose job it is to construct
- these pointers (as shown in the April article), or if the code is in
- a resource, can use the definitions in “Mixed Mode.r” to place a
- Routine Descriptor in front of the code.
-
- If you want to leave the PowerPC code alone, the 68K code can use a
- Mixed Mode A-Trap to create the routine descriptor. The bad news is
- this: blindly calling “NewRoutineDescriptor” won’t do what you want.
- (When compiling for the 68K, NewRoutineDescriptor is an “null” macro
- that just returns the supplied procedure pointer.) The solution is
- to copy the definition of NewRoutineDescriptor, and convert the
- contents of the “THREEWORDINLINE” macro into an actual inline.
-
- The result of all this work looks like this:
-
-
- #if USES68KINLINES
- pascal UniversalProcPtr InlineNewRoutineDescriptor(
- ProcPtr theProc,
- ProcInfoType theProcInfo,
- ISAType theISA)
- = {0x303C, 0x0000, 0xAA59};
- #endif
-
- typedef void (*OurProcPtr)(short);
-
- void CallPowerProc (ProcPtr powerCodeAddress,
- short onlyParameter)
- {
- OurProcPtr ourUPP;
- short procInfo = kCStackBased |
- STACK_ROUTINE_PARAMETER(1, kTwoByteCode);
-
- #if USES68KINLINES
- ourUPP=(OurProcPtr) InlineNewRoutineDescriptor(
- powerCodeAddress,
- procInfo,
- kPowerPCISA);
- #else
- // We’re compiling for PowerPC -- see the comments below
- ourUPP= (OurProcPtr) NewRoutineDescriptor(
- powerCodeAddress,
- procInfo,
- kPowerPCISA);
- #endif
- CallUniversalProc((UniversalProcPtr)ourUPP, procInfo, onlyParameter);
- // If you *know* this is 68K code, you could just use: ourUPP(onlyParameter)
- // but using CallUniversalProc covers the possibility that this could be compiled
- // for PowerPC some day without changing the sources
- }